<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程终止</title>
    <#include "/pubHeadStyle.html">
</head>
<body>

<div class="ccpui-tablesize user">
    <table class="layui-table">
        <colgroup>
            <col width="10">
            <col width="200">
        </colgroup>
        <tbody>
        <tr id="message">
        </tr>
        </tbody>
    </table>
</div>
<div style="text-align: center;position: absolute;bottom: 15px;width: 100%;">
    <a class="layui-btn" lay-event="endProcess" id="endProcess">
        <i class="layui-icon"></i>
        <span>确定</span>
    </a>
    <a class="layui-btn layui-btn-danger" id="close">
        <i class="layui-icon"></i>
        <span>取消</span>
    </a>
</div>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer','commons',  'setter'], function (d) {
        var layer = layui.layer;
        var $ = layui.$;
        var setter = layui.setter;
        var commons = layui.commons;

        var taskId = "${taskId}";

        endProcess();

        function endProcess() {
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath + "task/isTaskExsit?taskId=" + taskId+"&meno=",
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        $('#message').html('<th class="layui-bg-gray">不能终止原因</th><td><textarea name="desc" placeholder="请输入内容" class="layui-textarea" style="color: #af0000" disabled>' + data.message + '</textarea></td>');
                        $('#sendMethod').hide();
                        $('#endProcess').hide();
                    } else {
                        $('#message').html('<th class="layui-bg-gray">终止原因</th>  <td><textarea name="desc" placeholder="请输入内容" class="layui-textarea" id="endProcessReason"></textarea></td>');
                    }
                },
                error: function (XMLHttpRequest) {
                    layer.alert("操作失败！" + XMLHttpRequest.status);
                }
            })
        }

        $("#endProcess").click(function () {
            if ($('#endProcessReason').val() != null && $('#endProcessReason').val() != '') {
                layer.confirm("确认要终止该实例吗？", {title: '终止确认'}, function () {
                    $.ajax({
                        url: serverPath.workflowPath + setter.workflowLinkPath + "task/endProcess?taskId=" + taskId+ "&memo=" + $('#endProcessReason').val(),
                        type: "post",
                        dataType: 'json',
                        success: function (result) {
                            if (commons._filterRecord(result)) {
                                layer.open({
                                    title: '提示信息'
                                    ,content: result.msg
                                    ,yes: function(index, layero){
                                        parent.parent.layer.closeAll();
                                    }
                                });
                            } else {
                                layer.open({
                                    title: '提示信息'
                                    ,content: result.msg
                                    ,yes: function(index, layero){
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    }
                                });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert("操作失败！" + XMLHttpRequest.status);
                        }
                    });
                });

            } else {
                layer.open({
                    title: '提示'
                    , content: '必须填写终止原因！'
                });
            }

        });

        $("#close").click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

    })


</script>
</body>
</html>

